﻿using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Travel.CommonUtil;
using Travel.Data.Dtos;
using Travel.Data.Entity;
using Travel.Data.Inputs;

namespace Travel.Data.Profiles
{
    public class UserProfile : Profile

    {
        public UserProfile() {

            CreateMap<TabUser, UserDto>().ForMember(c=>c.RoleName,opt=>opt.MapFrom(src=>src.Role.RoleName)).ForMember(c => c.Mobile, opt => opt.MapFrom(src => FormatUtil.TxtReplace(src.Mobile,3,4,'*')));
            CreateMap<RegisterInput, TabUser>(); 
            CreateMap<UserProfileInput, TabUser>().ForMember(c=>c.Username,opt=>opt.Ignore());//忽略Username 映射

            CreateMap<UserAddOrUpdataInput, TabUser>().ForMember(c=>c.CreatedUserId,p=>p.MapFrom(s=>s.LoginUserId)).ForMember(c => c.UpdatedUserId, p => p.MapFrom(s => s.LoginUserId));

            CreateMap<MenuButtonInput, TabMenuButton>().ForMember(c => c.CreatedUserId, p => p.MapFrom(s => s.LoginUserId)).ForMember(c => c.UpdatedUserId, p => p.MapFrom(s => s.LoginUserId));
            CreateMap<MenuModuleInput, TabMenuModule>().ForMember(c => c.CreatedUserId, p => p.MapFrom(s => s.LoginUserId)).ForMember(c => c.UpdatedUserId, p => p.MapFrom(s => s.LoginUserId));
            CreateMap<TabMenuModule, MenuModuleDto>();
            CreateMap<TabMenuButton, MenuButtonDto>().ForMember(c => c.MenuModuleName, p => p.MapFrom(s => s.MenuModule.ModuleName));

            CreateMap<TabMenuModule, LeftMenuDto>();
        }   
    }
}
